package ano.it.service.impl;

import ano.it.dao.DeviceDao;
import ano.it.entity.PageResult;
import ano.it.entity.QueryPageBean;
import ano.it.pojo.Device;
import ano.it.service.DeviceService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service(interfaceClass = DeviceService.class)
public class DeviceServiceImpl implements DeviceService {
    @Autowired
    private DeviceDao deviceDao;

    @Override
    public void add(Device device) {
        deviceDao.add(device);
    }

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<Device> page=deviceDao.selectByCondition(queryPageBean.getQueryString());
        long total=page.getTotal();
        List<Device> rows=page.getResult();
        return new PageResult(total,rows);
    }

    @Override
    public void deleteById(Integer id) {
        deviceDao.deleteById(id);
    }

    @Override
    public void edit(Device device) {
        deviceDao.update(device);
    }

    @Override
    public Device findById(Integer id) {
        return deviceDao.findById(id);
    }

    @Override
    public List<Device> findAll() {
        return deviceDao.findAll();
    }
}
